package com.Object;

/**
 * @Author 小闽
 * @Date 2024/8/14 17:38
 * @PackageName: com
 * @ClassName: ToString
 * @Description: toString方法
 * @Version 1.0
 */
public class ToString {
    public static void main(String[] args) {
        Monster monster = new Monster("小黑", "巡山", 6000);
        System.out.println(monster.toString() + monster.hashCode());
        System.out.println(monster);
    }
}

class Monster{
    private String name;
    private String job;
    private double sal;

    public Monster(String name, String job, double sal) {
        this.name = name;
        this.job = job;
        this.sal = sal;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getJob() {
        return job;
    }

    public void setJob(String job) {
        this.job = job;
    }

    public double getSal() {
        return sal;
    }

    public void setSal(double sal) {
        this.sal = sal;
    }

    /**
     * 重写toString方法，一般是把对象的属性输出
     * @return
     */
    @Override
    public String toString() {
        return "Monster{" +
                "name='" + name + '\'' +
                ", job='" + job + '\'' +
                ", sal=" + sal +
                '}';
    }
}